<?php

use yii\db\Migration;

/**
 * Class m180727_031207_create_comments_score_history
 */
class m180727_031207_create_comments_score_history extends Migration
{
    private function createDbs(){
        $dbs = [];
        $dbs_info =\Yii::$app->params['db'];
        foreach($dbs_info as $k=>$v){
            $dbs[$k] = \Yii::createObject($v);
        }
        return $dbs;
    }
    public function safeUp()
    {
        $dbs = $this->createDbs();
        foreach ($dbs as $v) {
            $this->db = $v;
            $this->createTable('{{%comments_score_history}}',[
                'id' => $this->primaryKey()->notNull().' COMMENT \'自增id\'',
                'type' => $this->smallInteger(2)->defaultValue(0)->comment('类型 '),
                'object_id' => $this->integer(11)->defaultValue(0)->comment('目标id'),
                'score' => $this->float(2)->defaultValue(0)->comment('评分'),
                'month' => $this->string(20)->defaultValue(0)->comment('月份'),
                'created_at' => $this->integer(11)->defaultValue(0)->comment('创建时间'),
            ]);
        }
    }

    public function safeDown()
    {
        $dbs = $this->createDbs();
        foreach ($dbs as $v) {
            $this->db = $v;
            $this->dropTable('{{%comments_score_history}}');
        }
    }
}
